WinForms charting controls support built-in chart serialization, a feature that enables users to persist a complete chart definition to a single XML string, then reload it in the same or a different .NET application. By leveraging the .NET XmlSerializer, it works seamlessly across all .NET platforms.
Note: The FinancialChart control does not support serialization.
The feature uses two static methods of C1.Chart.Serialization.Serializer class:
To enable the extension methods, add the namespace at the top of the code file. The following code demonstrates how to persist and restore a FlexChart with its Data.
C# |
Copy Code
|
---|---|
// add namespace to use extension serialization methods using C1.Chart.Serialization; // create charts ... // Save chart var xml = flexChart.SerializeToXml(); // Later or elsewhere… // Restore chart definition in new instance of chart var newChart = new FlexChart(); newChart.DeserializeFromXml(xml); |
The following code demonstrates how to share definition between two FlexPie.
C# |
Copy Code
|
---|---|
// Save only formatting, omit data var xml = flexPie.SerializeToXml(false); // Load layout into another chart without changing its data anotherFlexPie.DeserializeFromXml(xml); |
Note: If serializeData is set to false, the data will not be saved during serialization. Ensure you rebind or supply the data manually before or after deserialization.